package com.bq.server.tree.multinode;

import com.bq.server.tree.JsonSerializable;
import com.bq.server.tree.Tree;
import com.bq.server.tree.TreeNode;

import java.util.Collection;

/**
 * jackson 序列化实现
 *
 * @author: ChenSH
 * @date: Create by in 6:19 下午 2020/1/6
 */
public class JsonLinkedMultiTreeNode<ID, T extends Tree<ID>> extends LinkedMultiTreeNode<T> implements JsonSerializable<T>, Tree<ID> {

    public JsonLinkedMultiTreeNode(T data) {
        super(data);
    }


    @Override
    public T getData() {
        return super.data();
    }

    @Override
    public Collection<? extends TreeNode<T>> getChildren() {
        Collection<? extends TreeNode<T>> subtrees = subtrees();
        if (subtrees.isEmpty()) {
            return null;
        }
        return subtrees;
    }

    /**
     * 有叶子节点
     */
    @Override
    public boolean isHasChildren() {
        return !isLeaf();
    }


    @Override
    public ID getId() {
        return data().getId();
    }

    @Override
    public ID getParentId() {
        return data().getParentId();
    }

    @Override
    public String getName() {
        return data().getName();
    }
}
